<template>
  <el-main>
   {{product.name}}
   {{product.price}}
    <el-input-number v-model="num" @change="handleChange" :min="1" :max="99" label="描述文字"></el-input-number>
    <el-button @click="add">加入购物车</el-button>
  </el-main>

</template>

<script>
export default {
  name: "Login",
  data() {
    return {
      product:{},
      num: 0,

    }
  },
  methods:{
    add() {
      this.axios.get('/cart/cart/add',{params:{productId:this.product.id, num: this.num}}).then(res=>{
        this.$message.success("加入购物车成功");
        this.$router.push('/mycart')
      })
    },
  },
  created: function () {
    let query = this.$route.query;
    console.log(query)
    this.axios.get('/product/t-m4-product/getById', {params:{id: query.id}}).then(res => {
      this.product = res.data.data;
    })
  }
}
</script>

<style scoped>
.time {
  font-size: 13px;
  color: #999;
}

.bottom {
  margin-top: 13px;
  line-height: 12px;
}

.button {
  padding: 0;
  float: right;
}

.image {
  width: 100%;
  display: block;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}
</style>